<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>加入表单元素 - 数据表格</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>组件</cite></a>
        <a><cite>数据表格</cite></a>
        <a><cite>加入表单元素</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">当前模板所有页面</div>
                <div class="layui-card-body">
                    <div style="padding-bottom: 10px;">
                        <button class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button>
                        <a class="layui-btn layuiadmin-btn-admin" lay-href="/admin/template/page/add.do?id=${id!}" lay-text="添加管理员">添加</a>
                    </div>
                    <table class="layui-hide" id="test-table-form"></table>

                    <script type="text/html" id="userTpl">
                        <a lay-href="/admin/user/{{ d.userId }}" lay-tips="{{ d.nickname }}的详细信息" lay-text="用户详情" class="fly-link">{{ d.nickname }}</a>
                    </script>

                    <script type="text/html" id="test-table-checkboxTpl">
                        <!-- 这里的 checked 的状态只是演示 -->
                        <input type="checkbox" name="lock" title="启用" lay-filter="test-table-lockDemo"
                               value="{{d.id}}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.id== 10006
                               ? '' : 'checked' }}>
                    </script>
                    <script type="text/html" id="pageTypeTpl">
                        {{#  if(d.pageType == 0){ }}
                        <button class="layui-btn layui-btn-xs">首页模板</button>
                        {{# } else if(d.pageType == 1) { }}
                        <button class="layui-btn layui-btn-xs">频道封面</button>
                        {{# } else if(d.pageType == 2) { }}
                        <button class="layui-btn layui-btn-xs layui-btn-normal">列表模板</button>
                        {{# } else if(d.pageType == 3) { }}
                        <button class="layui-btn layui-btn-xs layui-btn-warm">内容模板</button>
                        {{# } else if(d.pageType == 4) { }}
                        <button class="layui-btn layui-btn-xs layui-btn-primary">单独页面模板</button>
                        {{#  } }}
                    </script>
                    <script type="text/html" id="operateTpl">
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="/admin/template/page/edit.do?id={{d.id}}" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
<script>
    layui.config({
        base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.$;

        table.render({
            elem: '#test-table-form'
            , url: '/admin/template/page/listData.do'
            ,where:{templateId:"${id!}"}
            , cellMinWidth: 80
            , cols: [[
                {type: 'numbers'}
                , {type: 'checkbox'}
                , {field: 'id', title: 'ID', width: 100, unresize: true, sort: true}
                , {field: 'templateName', title: '页面名称'}
                , {field: 'remark', title: '模板说明'}
                , {field: 'expireTime', title: '所属模型',minWidth: 120}
                , {field: 'pageType', align:'center', title: '页面类型', width: 120, templet: '#pageTypeTpl'}
                , {field: 'addTime', align:'center', title: '添加时间', minWidth: 120, sort: true}
                , {field: 'state', align:'center', title: '模板状态', templet: '#test-table-checkboxTpl', unresize: true}
                ,{title:'操作', align:'center',  templet: '#operateTpl', unresize: true}
            ]]
            , page: true
        });

        //监听性别操作
        form.on('switch(test-table-visibleDemo)', function (obj) {
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
            console.log("==============" + this.value + "==================" + obj.elem.checked + "=======" + obj.othis)
            json = table.clearCacheKey(json);
            console.log(json); //当前行数据
        });

        //监听锁定操作
        form.on('checkbox(test-table-lockDemo)', function (obj) {
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);

            json = table.clearCacheKey(json);
            console.log(json); //当前行数据
        });

    });
</script>
</body>
</html>